<template>
  <div class="search">
    <el-form :inline="true" :model="searchParams">
      <el-form-item>
        <el-popover
          class="select"
          placement="bottom-start"
          width="300"
          trigger="hover"
        >
          <div class="type-list">
            <div
              v-for="(type, index) in typeList"
              :key="index"
              @click="selectedType(type)"
            >
              <span>{{ type }}</span>
            </div>
            <button class="clear" @click="clear">清<span>空</span></button>
          </div>
          <el-button
            style="width: 5%"
            icon="el-icon-arrow-down"
            slot="reference"
          ></el-button>
        </el-popover>
      </el-form-item>
      <el-form-item class="type">
        <el-input
          readonly
          placeholder="类 型"
          v-model="searchParams.type"
        ></el-input>
      </el-form-item>
      <el-form-item class="name">
        <el-input
          v-model="searchParams.name"
          placeholder="搜索关键字"
        ></el-input>
      </el-form-item>
      <el-form-item class="searchBtn" >
        <el-button
          icon="el-icon-search"
          class="css-button-shadow-border--red"
          @click="searches"
          >搜 索</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "SearchHeader",
  data() {
    return {
      typeList: [
        "布  艺",
        "皮  艺",
        "纸  艺",
        "木  艺",
        "饰  品",
        "编  织",
        "刺  绣",
        "雕  塑",
        "模  型",
        "橡皮章",
        "羊毛毡",
        "旧物改造",
        "烘  培",
        "陶  艺",
        "手  绘",
        "滴  胶",
        "金  属",
        "电  子",
        "园  艺",
        "其  他",
      ],
    };
  },
  computed: {
    ...mapState("worksInfo", ["searchParams"]),
  },
  methods: {
    selectedType(type) {
      this.searchParams.type = type;
    },
    clear() {
      this.searchParams.type = "";
    },
    searches(){
        console.log("传输数据");
        this.$emit("searchInput",this.searchParams)
    }
  },
  mounted(){
    this.searches();
  }
};
</script>

<style scoped>
.search {
  width: 30%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem auto 1rem auto;
  background-color: #fff;
}
.el-form >>> .el-form-item {
  margin: 0;
}
/* type输入框 */
.type >>> .el-input input {
  width: 5.5em;
  padding: 0.5em;
  letter-spacing: 1.5px;
  text-align: center;
  border: 0;
  border-radius: 0;
  color: #ef233c;
}
/* 清空选择器 */
.clear {
  background-color: tomato;
  border-radius: 5px;
  line-height: 2em;
  font-style: 1.2em;
  text-align: center;
  border: 0;
  color: #fff;
  padding: 0 0.5em;
}
.clear span {
  margin-left: 1em;
}
.clear:hover {
  cursor: pointer;
}
/* 搜索输入框 */
.name >>> .el-input input {
  /* background-color: rgba(209, 209, 209, 0.388); */
  width: 100%;
  letter-spacing: 1.5px;
  border: 0;
  border-left: 2px;
  border-radius: 0;
}
.name >>> .el-input input:focus {
  /* background-color: rgba(255, 255, 255, 0.247); */
  border: 0;
  border-radius: 0;
}

.searchBtn >>> .el-button {
  /* background-color: rgba(255, 255, 255, 0.247); */
  border-left: 0;
  border-bottom: 0;
  border-radius: 0;
  position: absolute;
}
.select >>> .el-button {
  border: 0;
  border-bottom: 0;
  border-radius: 0;
  margin: 0;
}
.select >>> .el-button:hover {
  background-color: #fff;
  color: #ec4731f3;
  border-left: 0;
  border-bottom: 0;
  border-radius: 0;
}

.type-list {
  height: auto;
  width: 100%;
  padding-left: 1rem;
}
.type-list div {
  height: 30px;
  line-height: 1.5em;
  letter-spacing: 0.1rem;
  margin-bottom: -5px;
  cursor: pointer;
  /* // 这里是控制显示几列的地方 3列就是 1/3 = 33% */
  width: 33%;
  float: left;
}
.type-list div:hover {
  color: #ef233c;
}
.type-list span {
  fill: currentColor;
  overflow: hidden;
}

.css-button-shadow-border--red {
  min-width: 130px;
  height: 40px;
  color: #fff;
  padding: 5px 10px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  display: inline-block;
  outline: none;
  border-radius: 5px;
  border: none;
  box-shadow: inset 2px 2px 2px 0px rgba(255, 255, 255, 0.5),
    7px 7px 20px 0px rgba(0, 0, 0, 0.1), 4px 4px 5px 0px rgba(0, 0, 0, 0.1);
  background: #ec4731f3;
}
.css-button-shadow-border--red:hover {
  background-color: #ef233c;
}
.css-button-shadow-border--red:active {
  top: 2px;
}
</style>
